<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
require_once("Writer.php");
//Includes
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("platinumgrid/jtplatinumgrid.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class route_emp_fuel_list extends Page
{
       public $JSDelete = null;
       public $lblempname = null;
       public $lblyear = null;
       public $Label48 = null;
       public $lblempid = null;
       public $JTExcelEmpFuel = null;
       public $imgBack = null;
       public $btnAdd = null;
       public $btnPrint = null;
       public $btnExport = null;
       public $btnSearch = null;
       public $edSearch = null;
       public $Image4 = null;
       public $hfEmpId = null;
       public $Image1 = null;
       public $JTSiteTheme1 = null;
       public $JTEmpFuel = null;
       function btnPrintJSClick($sender, $params)
       {

       ?>
       emp_id = document.getElementById('hfEmpId').value;
       window.open('print_emp_fuel.php?emp='+emp_id,'popup','width=850,height=768,scrollbars=yes,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0');

       <?php

       }

       function JTExcelEmpFuelShow($sender, $params)
       {
        $this->excel_grid_fill();


       }

       function btnExportClick($sender, $params)
       {
       $this->JTExcelEmpFuel->exportGridToXLSDownload("Employee_Fuel_List.xls");
       }

       function imgBackJSClick($sender, $params)
       {

       ?>
       document.location.href = "route_emp_list.php";

       <?php

       }

       function imgBackJSMouseOver($sender, $params)
       {

       ?>
       document.images['imgBack'].src="image/btn_back2.png"

       <?php

       }

       function imgBackJSMouseOut($sender, $params)
       {

       ?>
       document.images['imgBack'].src="image/btn_back.png"

       <?php

       }

       function btnAddJSMouseOver($sender, $params)
       {

       ?>
       document.images['btnAdd'].src="image/add_new_blue.png"

       <?php

       }

       function btnAddJSMouseOut($sender, $params)
       {

       ?>
       document.images['btnAdd'].src="image/add_new.png"

       <?php

       }

       function btnExportJSMouseOver($sender, $params)
       {

       ?>
       document.images['btnExport'].src="image/excel2.png"

       <?php

       }

       function btnExportJSMouseOut($sender, $params)
       {

       ?>
       document.images['btnExport'].src="image/excel.png"

       <?php

       }

       function btnPrintJSMouseOver($sender, $params)
       {

       ?>
       document.images['btnPrint'].src="image/btn_print2.png";

       <?php

       }

       function btnPrintJSMouseOut($sender, $params)
       {

       ?>
       document.images['btnPrint'].src="image/btn_print.png";

       <?php

       }

       function edSearchJSClick($sender, $params)
       {

       ?>
       document.getElementById('edSearch').value = '';

       <?php

       }

       function JTEmpFuelShow($sender, $params)
       {
       $emp_id = $this->hfEmpId->getValue();
       $grid_arr = array();

       $query_fuel = "SELECT * FROM emp_fuel_tbl WHERE emp_id='".$emp_id."'
       AND (
       date LIKE '%".$this->edSearch->Text."%' OR
       plate LIKE '%".$this->edSearch->Text."%' OR
       brand LIKE '%".$this->edSearch->Text."%' OR
       type LIKE '%".$this->edSearch->Text."%' OR
       gallons LIKE '%".$this->edSearch->Text."%' OR
       price LIKE '%".$this->edSearch->Text."%' OR
       tot_cost LIKE '%".$this->edSearch->Text."%' OR
       miles LIKE '%".$this->edSearch->Text."%'
       )
       ";
       $result_fuel = mysql_query($query_fuel) or die("SELECT EMP FUEL ".mysql_error());

       while($row_fuel = mysql_fetch_array($result_fuel))
       {
        $column1 = $row_fuel['date'];
        $column2 = $row_fuel['plate'];
        $column3 = $row_fuel['brand'];
        $column4 = $row_fuel['type'];
        $column5 = $row_fuel['gallons'];
        $column6 = $row_fuel['price'];
        $column7 = $row_fuel['tot_cost'];
        $column8 = $row_fuel['miles'];

        $tools = "<img onClick='deleteJS(".$row_fuel['autoid'].")' src='image/delete.png' title='Delete' border='' style='cursor:pointer'></a>";

        $id = $row_fuel['autoid'];

        $edit_date = "<a href='emp_rfuel_edit.php?autoid=".$id."&emp=".$this->hfEmpId->getValue()."'>".$column1."</a>";

        if($_SESSION['access_route']==1)
        {
        $grid_arr[] = array(
        "Date"=>$edit_date,
        "Vehicle"=>$column2,
        "Brand"=>$column3,
        //"Type"=>$column4,
        "Liters"=>$column5,
        "Price/Liter"=>$column6,
        "Total"=>$column7
        );
        }

        if($_SESSION['access_route']==2)
        {
        $grid_arr[] = array(
        "Date"=>$edit_date,
        "Vehicle"=>$column2,
        "Brand"=>$column3,
        //"Type"=>$column4,
        "Liters"=>$column5,
        "Price/Liter"=>$column6,
        "Total"=>$column7,
        //"Km/Hrs"=>$column8
        "Tools"=>$tools
        );
        }

       }
       $this->JTEmpFuel->setCellData($grid_arr);
       }

       function route_emp_fuel_listCreate($sender, $params)
       {
       $emp_id = $_GET['emp'];
       $this->hfEmpId->setValue($emp_id);
       //$this->excel_grid_fill();

       if($_SESSION['access_route']==1)
       {
       $this->btnAdd->Visible=false;
       $this->btnExport->Left=951;
       $this->btnPrint->Left=878;
       }

       if($_SESSION['access_route']==2)
       {
       $this->btnAdd->Visible=true;
       $this->btnExport->Left=846;
       $this->btnPrint->Left=774;
       }

       $query_emp = "SELECT * FROM employee_tbl WHERE autoid='".$this->hfEmpId->getValue()."'";
       $result_emp = mysql_query($query_emp) or die("SELECT EMP".mysql_error());
       $row_emp = mysql_fetch_array($result_emp);

       $this->lblempid->Caption = $row_emp['emp_id'];
       $this->lblempname->Caption = $row_emp['lname'].','.$row_emp['fname'];



       $this->btnAdd->setLink('emp_rfuel_create.php?emp='.$this->hfEmpId->getValue());
       }

       function excel_grid_fill()
       {
       $emp_id = $this->hfEmpId->getValue();
       $grid_arr = array();
       $excel_arr = array();
       $query_fuel = "SELECT * FROM emp_fuel_tbl WHERE emp_id='".$emp_id."'";
       $result_fuel = mysql_query($query_fuel) or die("SELECT EMP FUEL ".mysql_error());

       $query_emp = "SELECT * FROM employee_tbl WHERE autoid='".$emp_id."'";
       $result_emp = mysql_query($query_emp) or die("SELECT EMP ".mysql_error());
       $row_emp = mysql_fetch_array($result_emp);

       $excel_arr[] = array(
        "1"=>"Name:",
        "2"=>$row_emp['lname'].','.$row_emp['fname'],
        "3"=>"",
        "4"=>"",
        "5"=>"",
        "6"=>"",
        "7"=>"",
        "8"=>""
        );

       $excel_arr[] = array(
        "1"=>"Job Title:",
        "2"=>$row_emp['job_title'],
        "3"=>"",
        "4"=>"",
        "5"=>"",
        "6"=>"",
        "7"=>"",
        "8"=>""
        );

       $excel_arr[] = array(
        "1"=>"",
        "2"=>"",
        "3"=>"",
        "4"=>"",
        "5"=>"",
        "6"=>"",
        "7"=>"",
        "8"=>""
        );

       $excel_arr[] = array(
        "1"=>"Date",
        "2"=>"Vehicle",
        "3"=>"Brand",
        "4"=>"Type",
        "5"=>"Liters",
        "6"=>"Price/Liter",
        "7"=>"Total",
        "8"=>"Km/Hrs"
        );

       while($row_fuel = mysql_fetch_array($result_fuel))
       {
        $column1 = $row_fuel['date'];
        $column2 = $row_fuel['plate'];
        $column3 = $row_fuel['brand'];
        $column4 = $row_fuel['type'];
        $column5 = $row_fuel['gallons'];
        $column6 = $row_fuel['price'];
        $column7 = $row_fuel['tot_cost'];
        $column8 = $row_fuel['miles'];

        $excel_arr[] = array(
        "1"=>$column1,
        "2"=>$column2,
        "3"=>$column3,
        "4"=>$column4,
        "5"=>$column5,
        "6"=>$column6,
        "7"=>$column7,
        "8"=>$column8
        );
       }
       $this->JTExcelEmpFuel->setCellData($excel_arr);
       }



}

global $application;

global $route_emp_fuel_list;

//Creates the form
$route_emp_fuel_list=new route_emp_fuel_list($application);

//Read from resource file
$route_emp_fuel_list->loadResource(__FILE__);

//Shows the form
$route_emp_fuel_list->show();

?>